import org.example.Main;
import org.example.PrintClass;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class Maintest {
    static Main main;

    @BeforeAll
    static void setUp()
    {
        main = new Main();
    }

    @AfterEach
    public void tearDown() {
        this.main  = null;
    }

    @Test
    void testGetFromPro() {
        PrintClass pr = new PrintClass();
        Class<?> targetClass = pr.getClass();//获取类名
        assertEquals(targetClass, main.getFromPro("/myapp.properties").getClass());//测试对象
        assertThrows(NullPointerException.class, ()->{
            Class<?> testClass = main.getFromPro("/wrong.properties").getClass();//类不存在时
        });
    }

    @Test
    void testGetMethod() {
        PrintClass pr = new PrintClass();
        assertTrue(main.getMethod(pr, null));
        try
        {
            main.getMethod(pr, "123");
        }//正确的时候输出123
        catch (Exception exception)
        {
            System.out.println("Exception");
        }//异常检测
    }

}